package game;

import com.jogamp.opengl.util.texture.Texture;
import com.jogamp.opengl.util.texture.TextureIO;
import java.io.File;
import java.io.IOException;
import javax.media.opengl.GL2;
import javax.media.opengl.GLException;

class TextureObject
{
    Texture tex;
    int x, y;
    int width, height;
    float angle = 0;
    float rotateX = 0; float rotateY = 0; float rotateZ = 0;
    GL2 gl;

    public TextureObject(int x, int y, int widht, int height, String data, GL2 gl)
    {
        this.x = x;
        this.y = y;
        this.width = widht;
        this.height = height;
        this.gl = gl;
        createTexture(data);
    }

    private void createTexture(String data)
    {
        try 
        {
            tex = TextureIO.newTexture(new File(data), false);
            tex.setTexParameteri(gl, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST);
            tex.setTexParameteri(gl, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST);
        } catch (IOException ex) 
        {
            System.err.println("Uploading textures failed!" + " " + data);
        } catch (GLException ex) 
        {
            System.err.println(ex); 
        }
    }

    public void bind(GL2 gl)
    {
        tex.bind(gl);
    }

    boolean render = true;
    public void draw(GL2 gl)
    {              
            // rotation                
            gl.glBegin(GL2.GL_QUADS); 

            // rendering
            gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f( x, y,  1.0f);
            gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f( x + width, y,  1.0f);
            gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f( x + width,  y + height,  1.0f);
            gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f( x,  y + height,  1.0f);

            gl.glEnd();       
            // rerotation
        
        
//        gl.glRotatef(rotateX, rotateY, rotateZ, -angle);
    }
}